var contr=angular.module('contr',[]);


contr.controller('shopCtrl',['$scope','shopData','$ionicScrollDelegate','$http','$state',function($scope,shopData,$ionicScrollDelegate,$http,$state){//首页
	shopData.shop($scope);
	shopData.shops($scope);
		$scope.disco=false;
		$scope.goBack=false;
		$scope.disappear=true;

	  $scope.top=function(){
		$ionicScrollDelegate.scrollTop(false);
	}
	$scope.discolor=function(e){
		if($ionicScrollDelegate.getScrollPosition().top>=1){
			$scope.disco=true;
		}else{
			$scope.disco=false;
		}
		if($ionicScrollDelegate.getScrollPosition().top>=300){
			$scope.goBack=true;
			$scope.disappear=false;
		}else {
			$scope.goBack=false;
			$scope.disappear=true;
		}


				
}


$scope.openSea=function(){	
			$state.go('search');
		}



}])
contr.controller('classifyCtrl',['$scope','$stateParams','shopData','$ionicScrollDelegate','$state',function($scope,$stateParams,shopData,$ionicScrollDelegate,$state){//分类

$scope.openSea=function(){	
			$state.go('search');
		}
$scope.ids=$stateParams.id;


	 
	$scope.clic=function(index){
		 shopData.pro(index);
	  }
$scope.goGoods=function(index){
	shopData.goods(index);
}

}])
contr.controller('classify1Ctrl',['$scope','$rootScope','shopData','$state',function($scope,$rootScope,shopData,$state){//分类1
	
	$scope.arr=JSON.parse(localStorage.getItem('User'));
	$scope.comm='综合';
	$scope.sales='销量';
	$scope.price='价格';
	$scope.com=true;
	$scope.pric=false;
	$scope.scree=false;
	$scope.getComm=function(id){//综合
			shopData.comm(id);
			$scope.com=true;
			$scope.color=false;
			$scope.pric=false;
			$scope.scree=false;

	}
	$scope.getSales=function(id){//销量
		shopData.sales(id);
		$scope.color=true;
		$scope.com=false;
		$scope.pric=false;
		$scope.scree=false;
	}
$scope.getPrice=function(id){//价格
		shopData.price(id);
		$scope.color=false;
		$scope.com=false;
		$scope.pric=true;
		$scope.scree=false;
	}

$scope.getScree=function(id){//筛选
		shopData.scree(id);
		$scope.color=false;
		$scope.com=false;
		$scope.pric=false;
		$scope.scree=true;
		$scope.shows=true;
	
	}

	$scope.openSea=function(){	
			$state.go('search');
		}
	  $scope.showz=function(){
		 $scope.shows=true;
		 $rootScope.nu.low='';
		$rootScope.nu.high='';
		$rootScope.geAdd=null;
		$rootScope.geBrand=null;
	}
	$scope.close=function(){
		$scope.shows=false;
	}



$scope.getProduct=function(id){
shopData.prod(id,$scope.arr[0].uid);

}





		Array.prototype.indexOf = function(val) {//去掉重复的东西
					for (var i = 0; i < this.length; i++) {
								if (this[i] == val) return i;
									}
								return -1;
						};
		Array.prototype.remove = function(val) {
						var index = this.indexOf(val);
								if (index > -1) {
									this.splice(index, 1);
						}
		};


$scope.Brand=[];
$scope.getBrand=function(index,id){//获取品牌ID
			if($('.li').eq(index).hasClass('z-li')){
				$('.li').eq(index).removeClass('z-li');
				 $scope.Brand.remove(id);
				  $rootScope.geBrand=$scope.Brand.join(',');
				    
			}
			else{
				$('.li').eq(index).addClass('z-li');
				$scope.Brand.push(id);
				 $rootScope.geBrand=$scope.Brand.join(',');
				  
			}
			
		

}

$scope.Add=[];
$scope.getAdd=function(inde,id){//获取地区ID
	
		if($('.Add').eq(inde).hasClass('z-li')){
				$('.Add').eq(inde).removeClass('z-li');
				$scope.Add.remove(id);
				 $rootScope.geAdd=$scope.Add.join(',');
				   
			}
			else{
				$('.Add').eq(inde).addClass('z-li');
				$scope.Add.push(id);
				$rootScope.geAdd=$scope.Add.join(',');
				  
			}


	}





 $rootScope.nu={low:'',high:''};
 $scope.scuss=function(){
 if($rootScope.nu.low>$rootScope.nu.high){
 		$rootScope.test=$rootScope.nu.low;
 		$rootScope.nu.low=$rootScope.nu.high;
 		$rootScope.nu.high=$rootScope.test;
 	}else{
 		shopData.srceeData($rootScope.id,$rootScope.geBrand,$rootScope.geAdd,$rootScope.nu.low,$rootScope.nu.high);
		 	$scope.shows=false;
		 	$rootScope.geAdd='';
			$rootScope.geBrand='';
			$scope.Add=[];
			$scope.Brand=[];
		 
			

 	}
 	


 }

}])
contr.controller('searchCtrl',['$scope','$ionicHistory',function($scope,$ionicHistory){//搜索栏
	 	$scope.back=function(){
			$ionicHistory.goBack();
}

}])


contr.controller('distributionCtrl',['$scope','$state','shopData',function($scope,$state,shopData){//分销中心
var arr=JSON.parse(localStorage.getItem('User'));

	shopData.distribution(arr[0].uid,$scope);//请求数据

$scope.share=function(){
	
	if(arr){
		$state.go('share');
		
	}else 
		{
		shopData.time($scope,3,1000,'请先登录')	
	}

}



$scope.goCommis=function(){
		$state.go('commission');
	}

}])

contr.controller('cartCtrl',['$scope','shopData','$rootScope','$state',function($scope,shopData,$rootScope,$state){//购物车

	var arr=JSON.parse(localStorage.getItem('User'));
	shopData.shopCha(arr[0].uid);//请求数据

	

	if(arr){
		$('.widCon').addClass('f-n');
		$scope.check=true;
		$scope.cha=true;
	}
	else {
		$('.widCon').removeClass('f-n');
		$scope.cha=false;
		$scope.check=false;
	}


	$scope.open=function(){
	if($scope.list==null){
		shopData.time($scope,2,1000,'你还没有选择商品');
		return;
	} else if(shopData.shopCha(arr[0].uid)==null){
		shopData.time($scope,2,1000,'你还没有选择商品');
		return;
	}else{
		$scope.shows=true;
	}

	
}


	$scope.back=function(){
	$scope.shows=false;
}


$scope.total=0;//合计
var x=0;


$scope.add=function(index,id){//加号
	$scope.total=0;
	// console.log(id);
	number=parseInt($('.numS').eq(index).html());
	if(number==parseInt($('.numS').eq(index).attr('data-nuber'))){
		return;
	}else {
		number+=1;
		shopData.number(id,number,arr[0].uid);
		x=$('.numS').eq(index).html(number);
		
		
		 $scope.inpu();
	}
	
}

$scope.minus=function(index,id){//减号
	var number=parseInt($('.numS').eq(index).html());
	if(number==1){
		return ;
	}else {

		number--;
		shopData.number(id,x,arr[0].uid);
		$('.numS').eq(index).html(number);
			
		$scope.inpu();
	}
	
}


$scope.checkAll=function(){//全选
		

if($('.sett-se').prop('checked')){
	var li=[];
	var cartiD=[];
	$('.sett-chec').prop('checked','true');
	$scope.inpu();
	$('.sett-screen').each(function(){
				var xxxx=$(this).find('.price').attr('data-id');
				var car=$(this).find('.price').attr('data-cart');
				li.push(xxxx);
				cartiD.push(car);
				$scope.lists=li.join(',');	//得到删除传过去的字符串
				$rootScope.cartId=cartiD.join(",");	//得到结算需要传过去id的字符串
			
			}	
		)

}else {
		$('.sett-chec').prop('checked',false);
		$scope.total=0;
		var li=null;
}


}

		Array.prototype.indexOf = function(val) {//去掉重复的东西
					for (var i = 0; i < this.length; i++) {
								if (this[i] == val) return i;
									}
								return -1;
						};
		Array.prototype.remove = function(val) {
						var index = this.indexOf(val);
								if (index > -1) {
									this.splice(index, 1);
						}
		};


$scope.list=[];//去删除的id值
$scope.cart=[];//去结算的cartid值
$scope.inpu=function(id,index,cart){//总计
	if($('.sett-chec').eq(index).prop('checked')){//删除功能
			$scope.list.push(id);
			 $scope.lists=$scope.list.join(',');//得到删除传过去的字符串
			 $scope.cart.push(cart);
			 $rootScope.cartId=$scope.cart.join(',');//得到去结算传过去的字符串

	}
	else {
			$scope.list.remove(id);
			 $scope.lists=$scope.list.join(',');//得到删除传过去的字符串
			  $scope.cart.remove(cart);
			 $rootScope.cartId=$scope.cart.join(',');//得到去结算传过去的字符串

	}
		$scope.total = 0;
		$('.sett-screen').each(function(){
			if($(this).find('.sett-chec').prop('checked')){
				var a=$(this).find('.price').html();
				var num=$(this).find('.numS').html();
				$scope.total+=a*num;
			$('.check').html('&yen;'+$scope.total);
			}
			
		})
		

 			
}
$scope.delete=function(){//删除功能
		shopData.del(arr[0].uid,$scope.lists);
		$scope.list=[];//清空传过去的ID字符串
		$scope.shows=false;
		 $window.location.reload();
}

$scope.check=function(){


	if($rootScope.cartId==null){
		return;
	}
	else if(!$rootScope.address_id){
		$state.go('addNew');
		return;
	}
	else if($rootScope.address_id){
		shopData.check($rootScope.cartId,arr[0].uid,$rootScope.address_id);
		$scope.cart=null;//清空传过去的ID字符串
		li=[];//清空传过去的ID字符串
		cartiD=[];//清空传过去的ID字符串
		$state.go('indent');
	}
}

	
}])
contr.controller('myCtrl',['$scope',function($scope){//个人中心
	var arr=JSON.parse(localStorage.getItem('User'));

	if(arr){
		$scope.user=true;
		$scope.noUser=false;
		$scope.userN=arr[0].userN;
		$scope.userN=$scope.userN.replace($scope.userN.slice(3,7),"****");
		
	}else {
		$scope.noUser=true;
		$scope.user=false;
	}





}])

contr.controller('commissionCtrl',['$scope','$state',function($scope,$state){//分销佣金

	$scope.goApply=function(){
		$state.go('apply');
	}
	
}])
contr.controller('detailsCtrl',['$scope','shopData',function($scope,shopData){//佣金明细
	var arr=JSON.parse(localStorage.getItem('User'));

	shopData.detail_cash(arr[0].uid,$scope);//请求数据
}])

contr.controller('withdrawalCtrl',['$scope',function($scope){//提现明细
	
}])
contr.controller('shareCtrl',['$scope',function($scope){//推广二维码
var arr=JSON.parse(localStorage.getItem('User'));

if(arr){
		jQuery(function(){//自动生成二维码

				jQuery('#output').qrcode(arr[0].uid);
		})
}else {

}




}])


contr.controller('referralsCtrl',['$scope','shopData',function($scope,shopData){//我的下线
	var arr=JSON.parse(localStorage.getItem('User'));

	shopData.offline_user(arr[0].uid,$scope);//请求数据
}])

contr.controller('voucherCtrl',['$scope',function($scope){//充值

	$scope.num=[    {'list':''},
					{'list':''},
					{'list':''},
					{'list':''},
					{'list':''},
					{'list':''}

			];
	
}])



// 我的中心的二级页面


contr.controller('personalCtrl',['$scope',function($scope){//个人资料
	
}])

contr.controller('intercalateCtrl',['$scope','$state',function($scope,$state){//设置
	$scope.open=function(){
		$scope.opens=true;
	}
	$scope.back=function(){
		$scope.opens=false;
	}
	$scope.go=function(){
		localStorage.removeItem("User");
		$state.go('begin');
	}

}])

contr.controller('voucherCtrl',['$scope',function($scope){//充值
	
}])

contr.controller('whollyCtrl',['$scope',function($scope){//订单中心
	
}])

contr.controller('coupnCtrl',['$scope',function($scope){//优惠卷
	
}])

contr.controller('applyCtrl',['$scope','$ionicHistory',function($scope,$ionicHistory){//提现申请
$scope.back=function(){
	$ionicHistory.goBack();
}
}])

contr.controller('mall',['$scope',function($scope){//积分商城
	
}])

contr.controller('securityCtrl',['$scope',function($scope){//账户安全
	
}])

contr.controller('certificationCtrl',['$scope',function($scope){//实名认证
	
}])

contr.controller('recharge',['$scope',function($scope){//充值记录
	
}])

contr.controller('browseCtrl',['$scope','shopData',function($scope,shopData){//浏览记录
	$scope.arr=JSON.parse(localStorage.getItem('User'));
	shopData.fpList($scope.arr[0].uid);
	$scope.getProduct=function(goods_id){
	shopData.prod(goods_id,$scope.arr[0].uid);
}
}])

contr.controller('personalCtrl',['$scope',function($scope){//个人资料
	$scope.arr=JSON.parse(localStorage.getItem('User'));
	$scope.userName=$scope.arr[0].userN;	
}])

contr.controller('collectCtrl',['$scope','shopData',function($scope,shopData){//我的收藏
	$scope.arr=JSON.parse(localStorage.getItem('User'));
	shopData.cList($scope.arr[0].uid);
	$scope.getProduct=function(goods_id){
	shopData.prod(goods_id,$scope.arr[0].uid);
}
	$scope.cancelc=function(cid){
		shopData.cancelc(cid,$scope.arr[0].uid);
	}
}])



contr.controller('modifyCtrl',['$scope',function($scope){//修改手机号
		$scope.arr=JSON.parse(localStorage.getItem('User'));
	$scope.userName=$scope.arr[0].userN;	
}])

contr.controller('voucherCtrl',['$scope','$ionicHistory',function($scope,$ionicHistory){//充值
	
	$scope.back=function(){
	$ionicHistory.goBack();
}


}])








// 订单中心





contr.controller('orderCtrl',['$scope',function($scope){//我的订单的待付款 
	
}])

contr.controller('deliveryCtrl',['$scope',function($scope){//我的订单的收货
	
}])

contr.controller('assessCtrl',['$scope',function($scope){//我的订单的评价
	
}])

contr.controller('immediatelyCtrl',['$scope',function($scope){//立即评价


	$scope.list=[1,2,3,4,5];
	$scope.ping=function(item){
		$scope.star=item;
		if($scope.star==1){
				$('.li').eq(0).addClass('yellow');
				$('.li').eq(1).removeClass('yellow');
				$('.li').eq(2).removeClass('yellow');
				$('.li').eq(3).removeClass('yellow');
				$('.li').eq(4).removeClass('yellow');

		}
		if($scope.star==2){
				$('.li').eq(1).addClass('yellow');
				$('.li').eq(0).addClass('yellow');
				$('.li').eq(2).removeClass('yellow');
				$('.li').eq(3).removeClass('yellow');
				$('.li').eq(4).removeClass('yellow');

		}
		if($scope.star==3){
				$('.li').eq(item-1).addClass('yellow');
				$('.li').eq(item-2).addClass('yellow');
				$('.li').eq(0).addClass('yellow');
				$('.li').eq(3).removeClass('yellow');
				$('.li').eq(4).removeClass('yellow');
		}
		if($scope.star==4){
				$('.li').eq(item-1).addClass('yellow');
				$('.li').eq(item-2).addClass('yellow');
				$('.li').eq(item-3).addClass('yellow');
				$('.li').eq(0).addClass('yellow');
				$('.li').eq(4).removeClass('yellow');
		}
		if($scope.star==5){
				$('.li').eq(item-1).addClass('yellow');
				$('.li').eq(item-2).addClass('yellow');
				$('.li').eq(item-3).addClass('yellow');
				$('.li').eq(item-4).addClass('yellow');
				$('.li').eq(0).addClass('yellow');
		}





	}
	
}])





















contr.controller('tradeCtrl',['$scope',function($scope){//换绑手机号
	
}])


contr.controller('orderCtrl',['$scope',function($scope){//我的订单的待付款
	
}])

contr.controller('amendCtrl',['$scope',function($scope){//修改登录密码
	
}])

contr.controller('mallCtrl',['$scope',function($scope){//积分商城
	
}])

// 设置页

contr.controller('pushCtrl',['$scope',function($scope){//推送
	
}])
contr.controller('aboutCtrl',['$scope',function($scope){//关于未来购
	
}])

// 关于未来购


contr.controller('helpCtrl',['$scope',function($scope){//使用帮助
	
}])

contr.controller('statmentCtrl',['$scope',function($scope){//特别声明
	
}])



// 消息中心

contr.controller('messageCtrl',['$scope','$ionicHistory',function($scope,$ionicHistory){//消息中心

$scope.back=function(){
	$ionicHistory.goBack();
}


	
}])
contr.controller('messCtrl',['$scope',function($scope){//通知中心
	
}])

contr.controller('logisCtrl',['$scope',function($scope){//通知中心
	
}])


// 个人资料


contr.controller('photoallCtrl',['$scope',function($scope){//最近照片
	
}])
contr.controller('nicknameCtrl',['$scope',function($scope){//修改昵称
	$scope.arr=JSON.parse(localStorage.getItem('User'));
	$scope.userName=$scope.arr[0].userN;
}])





// 地址管理

contr.controller('addressCtrl',['$scope','$rootScope','shopData','$state','$window','$ionicHistory',function($scope,$rootScope,shopData,$state,$window,$ionicHistory){//地址管理

	$scope.rollback=function(){
		$ionicHistory.goBack();
	}
 	var arr=JSON.parse(localStorage.getItem('User'));

		shopData.addRss(arr[0].uid);
	$scope.redact=function(index){//编辑按钮
		shopData.editor(index);
			$state.go('editor');
		
	}
	$scope.del=function(index){//
		$scope.dels=true;
		console.log(index);
		$rootScope.delId=index;
	}
	$scope.close=function(){
		$scope.dels=false;
	}
	$scope.ensure=function(){
		shopData.amendDel($rootScope.delId);
		 $window.location.reload();
		$scope.dels=false;
	}
	$scope.sett=function(id,index){
		$('.p').html('设为默认地址');
	$('.p').eq(index).html('默认地址');
	$('.p').removeClass('deliv');
	$('.p').eq(index).addClass('deliv').siblings().removeClass('deliv');

		shopData.setDefault(id,arr[0].uid);
		 // $window.location.reload();

	}
			
	
}])

contr.controller('editorCtrl',['$scope','shopData','$ionicHistory','$state','$rootScope','$location',function($scope,shopData,$ionicHistory,$state,$rootScope,$location){//编辑地址 
   
var user=JSON.parse(localStorage.getItem("User"));
shopData.editor(user[0].uid);
 Zepto("#city-picker").cityPicker({
    toolbarTemplate: '<header class="bar bar-nav">\
    <button class="button button-link pull-right close-picker">确定</button>\
    <h1 class="title">选择收货地址</h1>\
    </header>'
  });

 var reg=/^1[35678][123456789]\d{8}$/;
$scope.save=function(){
	if(reg.test($scope.addRess.tel)==false){
		shopData.time($scope,2,1000,'请输入手机正确格式');
		return;
	}
	else{
		shopData.amendId($rootScope.editorId,user[0].uid,$rootScope.addRess.user,$rootScope.addRess.tel,$rootScope.addRess.serial,$rootScope.editorAdd,$rootScope.addRess.detail);
		$state.go('address');
	}
}

}])


contr.controller('addNewCtrl',['$scope','shopData','$ionicHistory','$state',function($scope,shopData,$ionicHistory,$state){//添加新地址
var user=JSON.parse(localStorage.getItem("User"));
$scope.addRess={user:'',tel:'',serial:'',detail:''};

 Zepto("#city-picker").cityPicker({
    toolbarTemplate: '<header class="bar bar-nav">\
    <button class="button button-link pull-right close-picker">确定</button>\
    <h1 class="title">选择收货地址</h1>\
    </header>'
  });

 // console.log();
 	var reg=/^1[35678][123456789]\d{8}$/;
$scope.back=function(){
	if(reg.test($scope.addRess.tel)==false){
		shopData.time($scope,2,1000,'请输入正确格式');
		return;
	}else{
		shopData.addNew(user[0].uid,$scope.addRess.user,$scope.addRess.tel,$scope.addRess.serial,$scope.addRess.detail,$('#city-picker').val());
		$scope.addRess.user='';
		$scope.addRess.tel='';
		$scope.addRess.serial='';
		$scope.addRess.detail='';
		$('#city-picker').val('北京 东城区');
		$ionicHistory.goBack();

		
	}
}





}])
contr.controller('areaCtrl',['$scope','shopData','$state','$rootScope',function($scope,shopData,$state,$rootScope){//选择地址	
	var arr=JSON.parse(localStorage.getItem('User'));
		shopData.addRss(arr[0].uid);
		$scope.switch=function(index){
			shopData.area(index);
			$rootScope.defaultId=index;
			$state.go('indent');
			// $scope.as=index;
		}
}])

contr.controller('streetCtrl',['$scope',function($scope){//选择街道
}])


contr.controller('collecCtrl',['$scope','$state',function($scope,$state){//秒杀

	
	
}])
contr.controller('productCtrl',['$scope','$ionicHistory','$state','shopData',function($scope,$ionicHistory,$state,shopData){//商品详情
	$scope.much=1;

	$scope.proDuc=JSON.parse(localStorage.getItem("pro"));

	var user=JSON.parse(localStorage.getItem("User"));

	$scope.add=function(){
		$scope.much++;
		$('.spanTwo').addClass('span');
	}
	$scope.minus=function(){
		if($scope.much==1){
			$('.spanTwo').removeClass('span');
			return;
		}else {
			$scope.much--;
		}
		

	}

	$scope.buy=function(){
			if(!user){
				$state.go('begin');
				return;
			}
	}


	console.log();
	$scope.ify=false;
	$scope.pros=true;
	$scope.ping=false;
	$scope.sh=false;
	$scope.shs=false;
	$scope.ifys=function(){
		$scope.ify=true;
		$scope.ping=false;
		$scope.pros=false;

	}
	$scope.pro=function(){
		$scope.ify=false;
		$scope.ping=false;
		$scope.pros=true;

	}
	$scope.ping=false;
	$scope.pings=function(){
		$scope.ping=true;
		$scope.ify=false;
		$scope.pros=false;

	}
	$scope.show=function(){
		$scope.sh=true;
	}
	$scope.shows=function(){
		if(!user){
			$state.go('begin');
		}
		else{
			$scope.shs=true;
		}
		
	}
	$scope.closes=function(){
		$scope.shs=false;
	}
	$scope.clse=function(){
		$scope.sh=false;
	}
	//console.log($scope.proDuc.id);

	$scope.back=function(){
	$ionicHistory.goBack();
	}
		$scope.addCha=function(){//加入购物车
			// alert(1);
		shopData.cha(user[0].uid,user[0].token,$scope.proDuc.id,$scope.much);
			$scope.shs=false;
			$scope.much=1;
		
	}
		$scope.focu='关注';
	$scope.focus=function(){//加入收藏
		if($('.foc').hasClass('focu')){
			$('.foc').removeClass('focu');
			$scope.focu='关注';
		}
		else {
			$scope.focu='已关注';
			$('.foc').addClass('focu');
			
		}

	}


}])


contr.controller('cosecradCtrl',['$scope',function($scope){//选择银行卡
}])
contr.controller('cardholderCtrl',['$scope',function($scope){//添加银行卡
}])





// 登录注册


contr.controller('beginCtrl',['$scope','$http','$rootScope','shopData','$state','$ionicHistory',function($scope,$http,$rootScope,shopData,$state,$ionicHistory){//登录页

	$scope.mode={num1:'',num2:''};
	$scope.back=function(){
	$ionicHistory.goBack();
}
	var arr=JSON.parse(localStorage.getItem('userName'));
	if(arr){
		$scope.mode.num1=arr[arr.length-1].userN;
	}
	if($scope.mode.num1){
			$scope.xxx=true;
	}
	


	$scope.chang1=function(){
		if($scope.mode.num1){
			$scope.xxx=true;
		}else{
			$scope.xxx=false;
		}
	}

	$scope.chang2=function(){
		if($scope.mode.num2){
			$scope.xx=true;
		}else{
			$scope.xx=false;
		}
	}


		$scope.eras=function(){
			$scope.isok1=false;
			$scope.mode.num1='';
			$scope.xxx=false;

		}
		$scope.erass=function(){
			$scope.isok2=false;
			$scope.mode.num2='';
			$scope.xx=false;

		}


$scope.begin = function(){
	shopData.begin($scope.mode.num1,$scope.mode.num2,$scope,$state);
}

		
	
}])
contr.controller('registerCtrl',['$scope','$interval','$state','$http','$rootScope','shopData',function($scope,$interval,$state,$http,$rootScope,shopData){//注册页
$scope.mode={num1:'',num2:''};

	$scope.chang1=function(){
		if($scope.mode.num1){
			$scope.isok1=true;
			$scope.x=true;
		}else{
			$scope.isok1=false;
			$scope.x=false;
		}
		$scope.anl();
	}
	$scope.chang2=function(){
		if($scope.mode.num2){
			$scope.isok2=true;
		}else{
			$scope.isok2=false;
			
		}
		$scope.anl();
	}
	$scope.anl=function(){
		if($scope.isok1&&$scope.isok2){
			$scope.shows=true;
			}else{
				$scope.shows=false;
			}
	}
	

	$scope.erase=function(){
			$scope.mode.num1='';
			$scope.x=false;
			$scope.shows=false;

			
		}

		$scope.isTime=false;
		$scope.yan='获取短信验证码';
		$scope.huo=function(){//获取短信验证码
			$scope.code=[];
			if($scope.isTime){
				return;
			}else{
				for(var i=0;i<4;i++){
					var num=parseInt(Math.random(11)*8);
					$scope.code.push(num);
				}
				$scope.code = $scope.code.join('');
				$http({
					method:'get',
					url:$rootScope.URL+'Home/UserCenter/code',
					params:{code:$scope.code,tel:$scope.mode.num1}
				}).success(function(data){
					

				}).error(function(data){
				})
				$scope.isTime=true;
				$scope.Time=30;
				$scope.time=$interval(function(){
						$scope.Time--;

						if($scope.Time==0){
							$interval.cancel($scope.time);
							$scope.yan='重新短信验证码';
							$scope.clo=false;
							$scope.isTime=false;
							return;

						}else {
							$scope.clo=true;

							$scope.yan='重新获取验证码  '+$scope.Time+" ";
						}
				},1000);

			}
		}


		var reg=/^1[35678][123456789]\d{8}$/;
		
	$scope.next=function(){

			if(reg.test($scope.mode.num1)==false){
				shopData.time($scope,3,1000,'手机号码不正确');
			}
			else if($scope.mode.num2.length<4){
				shopData.time($scope,3,1000,'验码错误');
			}
			else if($scope.mode.num2!=$scope.code){

				shopData.time($scope,3,1000,'验码错误');
			}
			
			else{

		 var arr=JSON.parse(localStorage.getItem("userName"));
            if(!arr){
            	arr=[];
            }
            var obj={
            	"userN":$scope.mode.num1
            	
            }
            arr.push(obj);
            localStorage.setItem("userName",JSON.stringify(arr));
				$state.go('register1');
			}

	}
	
	
}])


contr.controller('register1Ctrl',['$scope','$state','$interval','$http','$rootScope',function($scope,$state,$interval,$http,$rootScope){//注册页
var arr=JSON.parse(localStorage.getItem("userName"));

if(arr){
		$scope.user=arr[arr.length-1].userN;
}
	
	$scope.gos=function(){
		if($scope.shows){
			$scope.shows=false;
			$('.showx').attr("type","password");

		}else{
			$scope.shows=true;
			$('.showx').attr("type","text");
		}
	}
	

	$scope.paw='';

	$scope.change1=function(){
		$scope.x=true;
		$scope.showxx=true;
		if($scope.paw==''){
			$scope.showxx=false;
			$scope.x=false;
		}
	}

	$scope.erass=function(){
		$scope.paw='';
		$scope.x=false;
		$scope.showxx=false;
	}
	var reg=/^[0-9A-Za-z]{6,16}$/;

	$scope.register=function(){
		$scope.hintT=3;
		if($scope.paw==''){
			$scope.hintT=$interval(function(){
					$scope.hinT--;
						if($scope.hinT==0){
							$interval.cancel($scope.hintT);
								$scope.hint=false;
							return;

						}else {
							$scope.hint=true;
						}
				},1000);

			return;
		}else if(reg.test($scope.paw)==false){
			$scope.hintT=$interval(function(){
					$scope.hinT--;
						if($scope.hinT==0){
							$interval.cancel($scope.hintT);
								$scope.hint=false;
							return;

						}else {
							$scope.hint=true;
						}
				},1000);

				return;
		}else {
			$http({
					method:'post',
					url:$rootScope.URL+'Home/UserCenter/register',
					data:{account:$scope.user,password:$scope.paw},
				}).success(function(data){
					if(data.code == '1'){
						$state.go("begin" ,{},{ reload:true});
						
					}else{
						// alert(d.msg);
						$state.go('begin');
					}
				}).error(function(data){
					
				})

					
				
			
		}
		
	}
	
}])
contr.controller('retreveCtrl',['$scope','$interval','$http','$rootScope','shopData','$state',function($scope,$interval,$http,$rootScope,shopData,$state){//找回密码
$scope.mode={num1:'',num2:''};
	$scope.isok1=false;
	$scope.isok2=false;
	$scope.chang1=function(){
		if($scope.mode.num1){
			$scope.isok1=true;
			$scope.x=true;
		}else{
			$scope.isok1=false;
			$scope.x=false;
		}
		$scope.anl();
	}
	$scope.chang2=function(){
		if($scope.mode.num2){
			$scope.isok2=true;
		}else{
			$scope.isok2=false
		}
		$scope.anl();
	}
	$scope.anl=function(){
		if($scope.isok1&&$scope.isok2){
			$scope.shows=true;
			}else{
				$scope.shows=false;
			}
	}
	

	$scope.erase=function(){
			$scope.isok2=false
			$scope.isok1=false;
			$scope.mode.num1='';
			$scope.x=false;
			$scope.shows=false;
		}
	
	$scope.isTime=false;
		$scope.yan='获取短信验证码';
		$scope.huo=function(){//获取短信验证码
			$scope.code=[];
			if($scope.isTime){
				return;
			}else{
				for(var i=0;i<4;i++){
					var num=parseInt(Math.random(11)*8);
					$scope.code.push(num);
				}
				$scope.code = $scope.code.join('');
				$http({
					method:'get',
					url:$rootScope.URL+'Home/UserCenter/code',
					params:{code:$scope.code,tel:$scope.mode.num1}
				}).success(function(data){
				}).error(function(data){
				})
				$scope.isTime=true;
				$scope.Time=30;
				$scope.time=$interval(function(){
						$scope.Time--;

						if($scope.Time==0){
							$interval.cancel($scope.time);
							$scope.yan='重新短信验证码';
							$scope.clo=false;
							$scope.isTime=false;
							return;

						}else {
							$scope.clo=true;

							$scope.yan='重新获取验证码  '+$scope.Time+" ";
						}
				},1000);

			}
		}


		$scope.retreve=function(){
			if($scope.mode.num2.length<4){
					shopData.time($scope,3,1000,'验码错误');
				}
				else if($scope.mode.num2!=$scope.code){
					shopData.time($scope,3,1000,'验码错误');
				}
				else{
					$state.go('retreve1');
				}
		}
	
}])


contr.controller('retreve1Ctrl',['$scope',function($scope){//找回密码2
	var reg=/^[0-9A-Za-z]{6,16}$/;
	$scope.attrs='';
		$scope.scuss=function(){
		if(reg.test($scope.attrs)==false){
			alert(1);
		return;
		}else{
			alert('修改成功');
		}
	}
	
	$scope.shut=function(){
		if($scope.shuts){
			$scope.shuts=false;
			$('.z-c').attr("type","password");

		}else{
			$scope.shuts=true;
			$('.z-c').attr("type","text");
		}
		
		
	}


	$scope.chang1=function(){
		if($scope.attrs){
			$scope.x=true;
		}else{
			$scope.x=false;
		}
	}
		$scope.erase=function(){
			$scope.attrs='';
			$scope.x=false;
		}
	
}])
contr.controller('indentCtrl',['$scope','$state','$rootScope','shopData','$ionicHistory',function($scope,$state,$rootScope,shopData,$ionicHistory){//填写订单

var arr=JSON.parse(localStorage.getItem('User'));

		shopData.addRss(arr[0].uid);
		shopData.area($rootScope.defaultId);

shopData.check($rootScope.cartId,arr[0].uid,$rootScope.address_id);


$scope.ress=function(id){//选择地址
	$state.go('area');
	shopData.area(id);
	$rootScope.defaultId=id;


}
$rootScope.catr_can=0;
$scope.shut=function(){//选择积分
	// var catr_can=0;
	if($('.choo i').hasClass('i')){
		$('.choo i').removeClass('i');
		$rootScope.all_price+=$rootScope.can_cred;
		$rootScope.catr_can=0;

		}else{
		$('.choo i').addClass('i');
			
			$rootScope.catr_can=$rootScope.can_credit;
		$rootScope.all_price=parseFloat($rootScope.all_price-$rootScope.can_cred);
	}



}

$scope.sub=function(){//提交订单
		shopData.submit($rootScope.defaultId,$rootScope.cartId,arr[0].uid,$rootScope.catr_can,$rootScope.totals,$rootScope.postage,$rootScope.all_price);//提交订单的地址Id,商品Id

}
$scope.goBack=function(){//回到前一页
	$state.go('cart');

}


}])

contr.controller('menologyCtrl',['$scope','$ionicHistory',function($scope,$ionicHistory){//积分签到

var d = new Date();//获取日期
$scope.today=d.getDate();//获取当天
$scope.li=[];
 $scope.year=d.getFullYear(); 
$scope.month=d.getMonth()+1;
// 
var curMonthDays = new Date(d.getFullYear(), (d.getMonth()+1), 0).getDate();

for(var i=0;i<curMonthDays;i++){
$scope.li.push(i+1);
}

 var day1 = new Date();
 day1.setTime(day1.getTime()-24*60*60*1000);
 var s1 = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate();
//昨天的日期

  var day2 = new Date();//今天的日期
 day2.setTime(day2.getTime());
 var s2 = day2.getFullYear()+"-" + (day2.getMonth()+1) + "-" + day2.getDate();

var flag=true;
$scope.panT=function(){
	if(s1!=s2){
	$('.menologbBj div').removeClass('meology');
	var flag=false;
	}
}

var num=0;
var integral=0;//积分
$scope.panT();
$scope.qiandao=function(today){

	$(".span").each(function(){
	console.log(2);
})
	if(flag){
		$('.menologbBj div').addClass('meology');
		$('.curMonthDays ul li span').eq(today-1).addClass('span');
		num++;
		return;
	}
}




	$scope.rollback=function(){//回到前一页
		$ionicHistory.goBack();
	}



}])

contr.controller('logisticsCtrl',['$scope',function($scope){//物流详情
}])











contr.directive('accordion', function() {
    return {
        restrict : 'E',
        replace : true,
        template : '<p>设为默认地址</p>',
        transclude : true,
        scope : {},
        link : function(scope, element,attrs) {
           if(attrs.tid==attrs.deluid){

           	element.text("默认地址");
           }
        }
    }
});


